<!-- @format -->

<template>
	<div class="ma-content-block lg:flex justify-between p-4">
		<!-- CRUD 组件 -->
		<ma-crud :options="options" :columns="columns" ref="crudRef" >
			<template #dept_id="{ record }">
				<!-- 对标题加上 tag -->
				<a-tag color="blue">{{ record?.dept?.name }}</a-tag>
			</template>
			<template #operationBeforeExtend="{ record }">
				<a-link @click="watehouseRecord(record)" v-auth="['warehouse:orderRecord:rkmxs']">入库明细</a-link>
			</template>
		</ma-crud>
		<a-modal :mask-closable="false"  :footer="false" :width="1000" v-model:visible="visibleRecord">
			<template #title> 入库明细 </template>
			<WarehouseOrderrecord ref="warehouseRecordRef" />
		</a-modal>
	</div>
</template>
<script setup>
	import { ref, reactive } from "vue";
	import warehouseOrder from "@/api/warehouse/warehouseOrder";
	import { Message } from "@arco-design/web-vue";
	import tool from "@/utils/tool";
	import WarehouseOrderrecord from "@/views/warehouse/orderRecord/indexJzx.vue";
	import * as common from "@/utils/common";

	const crudRef = ref();
	const dept_id = ref(0);
	const warehouseRecordRef = ref();
	const visibleRecord = ref(false);

	//仓储明细
	const watehouseRecord = (currentRow) => {
		warehouseRecordRef.value.open(currentRow);
		visibleRecord.value = true;
	};

	const numberOperation = (newValue, id, numberName) => {
		warehouseOrder
			.numberOperation({ id, numberName, numberValue: newValue })
			.then((res) => {
				res.success && Message.success(res.message);
			})
			.catch((e) => {
				console.log(e);
			});
	};

	const open = (row) => {
		dept_id.value = row.dept_id;
		crudRef.value.crudSearchRef.resetSearch();
		crudRef.value.requestData();
	};
	const switchStatus = (statusValue, id, statusName) => {
		warehouseOrder
			.changeStatus({ id, statusName, statusValue })
			.then((res) => {
				res.success && Message.success(res.message);
			})
			.catch((e) => {
				console.log(e);
			});
	};

	const options = reactive({
		id: "flyos_warehouse_order",
		rowSelection: {
			showCheckedAll: true,
		},
		pk: "id",
		operationColumn: true,
		operationWidth: 160,
		isDbClickEdit: false,
		bordered: { cell: true },
		formOption: {
			viewType: "modal",
			width: 600,
		},
		api: warehouseOrder.getList,
		recycleApi: warehouseOrder.getRecycleList,
		add: {
			show: false,
			api: warehouseOrder.save,
			auth: ["warehouse:order:save"],
		},
		edit: {
			show: false,
			api: warehouseOrder.update,
			auth: ["warehouse:order:update"],
		},
		delete: {
			show: false,
			api: warehouseOrder.deletes,
			auth: ["warehouse:order:delete"],
			realApi: warehouseOrder.realDeletes,
			realAuth: ["warehouse:order:realDeletes"],
		},
		recovery: {
			show: false,
			api: warehouseOrder.recoverys,
			auth: ["warehouse:order:recovery"],
		},
		import: {
			show: false,
			url: "warehouse/order/import",
			templateUrl: "warehouse/order/downloadTemplate",
			auth: ["warehouse:order:import"],
		},
		export: {
			show: true,
			url: "warehouse/order/export",
			auth: ["warehouse:order:export"],
		},
		beforeRequest: (params) => {
			params.dept_id = dept_id.value;
		},
	});

	const columns = reactive([
		{
			title: "ID",
			dataIndex: "id",
			formType: "input",
			addDisplay: false,
			editDisplay: false,
			hide: true,
			commonRules: {
				required: true,
				message: "请输入ID",
			},
		},
		{
			title: "订单号",
			dataIndex: "order_no",
			formType: "input",
			align: "center",
			search: true,
			commonRules: {
				required: true,
				message: "请输入订单号",
			},
		},
		{
			title: "客户姓名",
			dataIndex: "dept_id",
			align: "center",
			formType: "select",
			dict: {
				// 远程通用接口请求，新版代码生成都有一个 remote 接口
				remote: "system/dept/remote",
				// 指定组件接收的props
				props: { label: "name", value: "id" },
				// 开启分页
				openPage: true,
				// 远程请求配置项
				remoteOption: {
					// 按用户名排序
					sort: { name: "desc" }, // 如果不指定排序方式，默认为正序排序
					// 设置查询的字段
					select: ["id", "name"],
					// 设置数据过滤
					filter: {
						type: ["=", 2],
						status: ['=',1]
					},
					// 关联模型
					relations: [],
				},
			},
		},
		// {
		//   title: "库存件数",
		//   dataIndex: "zong_number",
		//   align:'center',
		//   formType: "input-number",
		//   search: true,
		//   min: 0,
		//   max: 999999,
		//   step: 1
		// },
		// {
		//   title: "库存吨数",
		//   dataIndex: "zong_weight",
		//   align:'center',
		//   formType: "input-number",
		//   search: true,
		//   min: 0,
		//   max: 999999,
		//   step: 0.01,
		//   precision: 2
		// },
		// {
		//   title: "剩余件数",
		//   dataIndex: "yu_number",
		//   formType: "input-number",
		//   align:'center',
		//   search: true,
		//   min: 0,
		//   max: 999999,
		//   step: 1
		// },
		// {
		//   title: "剩余吨数",
		//   dataIndex: "yu_weight",
		//   align:'center',
		//   formType: "input-number",
		//   search: true,
		//   min: 0,
		//   max: 999999,
		//   step: 0.01,
		//   precision: 2
		// },
		{
			title: "状态",
			dataIndex: "status",
			align: "center",
			formType: "select",
			search: true,
			// commonRules: {
			//     required: true,
			//     message: "请输入状态"
			// },
			dict: {
				data: [
					{
						label: "仓储中",
						value: "1",
					},
					{
						label: "已完成",
						value: "2",
					},
				],
				translation: true,
				tagColors: { 1: "blue", 2: "green" },
			},
		},
		{
			title: "创建时间",
			dataIndex: "created_at",
			formType: "range",
			align: "center",
			search: true,
			addDisplay: false,
			editDisplay: false,
			showTime: true,
		},
		{
			title: "更新时间",
			dataIndex: "updated_at",
			formType: "date",
			addDisplay: false,
			editDisplay: false,
			hide: true,
			showTime: true,
		},
		{
			title: "删除时间",
			dataIndex: "deleted_at",
			formType: "date",
			addDisplay: false,
			editDisplay: false,
			hide: true,
			showTime: true,
		},
		{
			title: "更新者",
			dataIndex: "updated_by",
			formType: "input",
			addDisplay: false,
			editDisplay: false,
			hide: true,
		},
		{
			title: "创建者",
			dataIndex: "created_by",
			formType: "input",
			addDisplay: false,
			editDisplay: false,
			hide: true,
		},
	]);
	defineExpose({ open });
</script>
<script>
	export default { name: "warehouse:orderJzx" };
</script>
